/* this file convert certain pattern into tokens
 * ``` cpp
 *token_scanner ts(string pattern);
 ts.scan_tokens();
 vector<token> tokens = ts.get_tokens();

 * ```
*/
#ifndef _TOKEN_H
#define _TOKEN_H
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
enum class tokentype {
    WORD,
    LETTER,
    DIGIT,
    NUMBER,
    X,
    VAR,
    CONST
};

struct token {
    tokentype type;
    unsigned int count;
    std::string varname;

    token(tokentype type, unsigned int count, std::string varname);
    token(const token& t);
    std::string to_string();
};

class token_scanner {
private:
    int current;
    std::string input;
    std::vector<token> tokens;

    void scan_token();
    bool isEnd();
    char advance(); // take and consume first char
    char peek(); // take and conserve first char
    unsigned int take_count();
    void push_varname(std::string varname);
    void push_varname_zfill(std::string varname);
    void push_digit(std::string varname);
    void push_number(std::string varname);
    void push_letter(std::string varname);
    void push_word(std::string varname);
    void push_x(std::string varname);
    void push_const();
    std::string take_varname();
public:
    token_scanner(std::string input);
    void scan_tokens();
    std::string to_string();
    std::vector<token> get_tokens();
};
std::vector<token> scan_tokens(std::string input);
#endif
